package com.diankangwo.factory.controller;

import com.diankangwo.api.annotation.LoginUser;
import com.diankangwo.common.utils.R;
import com.diankangwo.factory.entity.TdMinMoneyLimit;
import com.diankangwo.factory.entity.TdUserinfo;
import com.diankangwo.factory.service.TdMinMoneyLimitService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/** （分销设置）最低提现金额Controller
 * Created by wuye on 2017/10/16.
 */
@RestController
@RequestMapping("/fac/limit")
public class TdMinMoneyLimitController {

    @Autowired
    private TdMinMoneyLimitService tdMinMoneyLimitService;


    /**
     * 添加最低提现金额
     * @param minmoney
     * @param content
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @RequiresPermissions("fac:limit:save")
    public R add(int minmoney, String content){
        TdMinMoneyLimit tdMinMoneyLimit = new TdMinMoneyLimit();
        tdMinMoneyLimit.setContent(content);
        tdMinMoneyLimit.setCreatetime(new Date());
        tdMinMoneyLimit.setCreateuser(0);
        tdMinMoneyLimit.setMinmoney(minmoney);
        tdMinMoneyLimitService.save(tdMinMoneyLimit);
        return R.ok();
    }

    /**
     * 根据ID查询最低提现金额
     * @param id
     * @return
     */
    @RequestMapping(value = "/findbyid",method = RequestMethod.POST)
    @RequiresPermissions("fac:limit:findbyid")
    public R findById(int id){
        TdMinMoneyLimit tdMinMoneyLimit = tdMinMoneyLimitService.findById(id);
        return R.ok().put("tdMinMoneyLimit",tdMinMoneyLimit);
    }


    /**
     * 修改最低提现金额
     * @param userinfo
     * @param minmoney
     * @param content
     * @return
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @RequiresPermissions("fac:limit:update")
    public R update(@LoginUser TdUserinfo userinfo,int id,int minmoney,String content){
        TdMinMoneyLimit tdMinMoneyLimit = tdMinMoneyLimitService.findById(id);
        tdMinMoneyLimit.setMinmoney(minmoney);
        tdMinMoneyLimit.setContent(content);
        tdMinMoneyLimitService.update(tdMinMoneyLimit);
        return R.ok();
    }
}
